/*
 * Copyright (c) 2020 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.classic.common.simple;

import com.github.clans.fab.FloatingActionButton;
import com.github.clans.fab.Label;
import com.github.clans.fab.util.Util;
import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import ohos.agp.components.Component;
import ohos.agp.utils.Color;
import ohos.app.Context;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

public class FloatingActionButtonTest {
    private FloatingActionButton mFloatingActionButton;
    private Context mContext;

    @Test
    public void testBundleName() {
        final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName();
        assertEquals("com.classic.common.simple", actualBundleName);
    }

    @Before
    public void setUp() {
        mContext = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext();
        mFloatingActionButton = new FloatingActionButton(mContext);
    }



    @Test
    public void measuredFABWidthAndHeightShouldNotBeZero() {
        assertNotEquals(0, mFloatingActionButton.calculateMeasuredWidth());
    }

    @Test
    public void shouldCreateCircleShapedDrawable() {
        assertNotNull(mFloatingActionButton.createCircleDrawable(Color.RED.getValue()));
    }

    @Test
    public void shouldSetColorNormal() {

        mFloatingActionButton.setColorNormal(Color.BLACK.getValue());
        assertEquals(Color.BLACK.getValue(), mFloatingActionButton.getColorNormal());

    }
    @Test
    public void shouldSetFABStateColors() {

        mFloatingActionButton.setColorRipple(Color.BLUE.getValue());
        assertEquals(Color.BLUE.getValue(), mFloatingActionButton.getColorRipple());
    }


    @Test
    public void shouldSetFABDisabledColor() {
        mFloatingActionButton.setColorDisabled(Color.RED.getValue());
        assertEquals(Color.RED.getValue(), mFloatingActionButton.getColorDisabled());
    }

    @Test
    public void shouldSetFABShadowColor() {
        mFloatingActionButton.setShadowColor(Color.RED.getValue());
        assertEquals(Color.RED.getValue(), mFloatingActionButton.getShadowColor());
    }

    @Test
    public void shouldSetFABShadowRadius() {
        mFloatingActionButton.setShadowRadius(1.0f);
        assertEquals(Util.vpToPx(mContext, 1.0f), mFloatingActionButton.getShadowRadius(), 0.0f);
    }
    @Test
    public void shouldShowFAB() {
        mFloatingActionButton.show(true);
        assertTrue(mFloatingActionButton.getVisibility() == Component.VISIBLE);
    }

    @Test
    public void shouldHideFAB() {
        mFloatingActionButton.hide(true);
        assertTrue(mFloatingActionButton.getVisibility() == Component.INVISIBLE);
    }

    @Test
    public void shouldSetFABLabelText() {
        mFloatingActionButton.setLabelText("test");
        assertEquals("test", mFloatingActionButton.getLabelText());
    }

    @Test
    public void shouldShowFABLabel() {
        mFloatingActionButton.setTag(new Label(mContext));
        mFloatingActionButton.setLabelVisibility(Component.VISIBLE);
        assertTrue(mFloatingActionButton.getLabelVisibility() == Component.VISIBLE);
    }

    @Test
    public void shouldHideFABLabel() {
        mFloatingActionButton.setTag(new Label(mContext));
        mFloatingActionButton.setLabelVisibility(Component.INVISIBLE);
        assertTrue(mFloatingActionButton.getLabelVisibility() == Component.INVISIBLE);
    }

    @Test
    public void shouldSetFABMaxProgress() {
        mFloatingActionButton.setMax(50);
        assertEquals(50, mFloatingActionButton.getMax());
    }

    @Test
    public void shouldShowBackgroundForFABProgress() {
        mFloatingActionButton.setShowProgressBackground(true);
        assertTrue(mFloatingActionButton.isProgressBackgroundShown());
    }

}